package com.spark.jwt.controller;

import com.spark.jwt.model.UserInfo;
import com.spark.jwt.util.JwtTokenUtil;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
public class Controller {

    @RequestMapping("/create")
    public String create() {
        UserInfo userInfo = new UserInfo(1L, "spark");
        return JwtTokenUtil.generateToken(userInfo);
    }

    @RequestMapping("/verify/{token}")
    public UserInfo verify(@PathVariable String token) {
        return JwtTokenUtil.getUserInfoFromToken(token);
    }
}
